﻿import QtQuick 2.0
import QtQuick.Controls 2.3

ListView {
    id:viewId
    property ListModel myModel
    property  int itemHeight: 30
    signal signalClickedItem(int index);
    model: myModel
    delegate: contactDelegate
    clip: true
    focus: true
    Component {
        id: contactDelegate
        Rectangle {
            width: viewId.width; height: itemHeight
            color: ma.containsMouse?"#F0F0F0":(viewId.currentIndex == index?"#F0F0F0":"#7F7F7F")
            Text {
                text: name;
                horizontalAlignment: Text.AlignHCenter;
                width: viewId.width
                verticalAlignment: Text.AlignVCenter
                anchors.centerIn: parent
                font.strikeout: true
                color: ma.containsMouse?"#21be2b":(viewId.currentIndex == index?"#21be2b":"#FFFFFF")
            }
            MouseArea{
                id:ma
                anchors.fill: parent
                hoverEnabled: true
                onClicked: {
                    console.log("clicked item ",index);
                    viewId.currentIndex = index;
                    signalClickedItem(index);
                }
            }
        }
    }
    ScrollBar.vertical: ScrollBar {
    }
    function moveToTop(){
        viewId.ScrollBar.vertical.postion=0;
    }
    function moveToBottom(){

    }
    onContentYChanged: {
        // 下拉刷新判断逻辑：已经到头了，还下拉一定距离
        if (contentY < originY){
            var dy = contentY - originY;
            if (dy < -14){
                //needReflesh = true;
            }
        }
        // 上拉加载判断逻辑：已经到底了，还上拉一定距离
        if (contentHeight>height && contentY-originY > contentHeight-height){
            var dy1 = (contentY-originY) - (contentHeight-height);
            if (dy1 > 8){
                console.log("load more ",dy1);
            }
        }
    }
}
